<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        * {
            box-sizing: border-box;
        }

        ul {
            list-style-type: none;
            padding: 0;
            margin: 0;
        }

        ul li {
            border: 1px solid #ddd;
            margin-top: -1px;
            /* Prevent double borders */
            background-color: #f6f6f6;
            padding: 12px;
            text-decoration: none;
            font-size: 18px;
            color: black;
            display: block;
            position: relative;
        }

        ul li:hover {
            background-color: #eee;
        }

        .close {
            cursor: pointer;
            position: absolute;
            top: 50%;
            right: 0%;
            padding: 12px 16px;
            transform: translate(0%, -50%);
        }

        .close:hover {
            background: #bbb;
        }
    </style>
</head>

<body>

    <h2>Closable List Items</h2>
    <p>Click on the "x" symbol to the right of the list item to close/hide it.</p>

    <ul>
        <li>Adele</li>
        <li>Agnes<span class="close">&times;</span></li>

        <li>Billy<span class="close">&times;</span></li>
        <li>Bob<span class="close">&times;</span></li>

        <li>Calvin<span class="close">&times;</span></li>
        <li>Christina<span class="close">&times;</span></li>
        <li>Cindy</li>
    </ul>

    
    <xmp style="font-size: 22px; font-weight: bolder;  margin-bottom: 66px;  color: black;  font-family: '微软雅黑';">
        必知必会 

        防止 2 条边框:
        margin-top: -1px;
    
        给 close 按钮轮流绑定 none 事件:
        for (i = 0; i < closebtns.length; i++) {
            closebtns[i].addEventListener("click", function () {
                this.parentElement.style.display = 'none';
            });
        }
    </xmp>

    <script>
        var closebtns = document.getElementsByClassName("close");
        var i;

        for (i = 0; i < closebtns.length; i++) {
            closebtns[i].addEventListener("click", function () {
                this.parentElement.style.display = 'none';
            });
        }
    </script>

</body>

</html>